<!--
以此组件进行v-model的封装基础
-->
<template>
  <el-switch v-model="switchValue" v-bind="$attrs" v-on="$listeners"></el-switch>
</template>

<script>
export default {
  name: 'mc-switch',
  data () {
    return {
    }
  },
  props:{
    //此处的value 就是父亲的v-model default:null 可以触发parent外为false
    'value' : {type:[Boolean,String,Number],default:null},
    'mcDefaultValue':{type:[Boolean,String,Number],default:null},
    'mcAllowNull':{type:Boolean,default:false},
  },
  watch:{

  },
  computed:{
    switchValue:{
      get:function (){
        if(this.value===null || typeof this.value=='undefined'){
          if(this.mcDefaultValue!==null){
            this.$emit("input",this.mcDefaultValue);
            return true;
          }else {
            if(this.mcAllowNull){
                this.$emit("input",null);
            }else{
                this.$emit("input",false);
                return false;
            }
          }
        }
        return this.value;
      },
      set:function (v){
        this.$emit("input",v);
      }
    }
  },
  mounted () {

  },
  methods:{

  }
}
</script>

<style lang="scss">

</style>
